/*
 * This file is part of shared-drawing.
 * shared-drawing is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option )
 * any later version. shared-drawing is distributed in the hope that it will
 * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 * You should have received a copy of the GNU General Public License along with 
 * shared-drawing. If not, see http://www.gnu.org/licenses/.
 */

package SharedDrawing;
import common.XmlConstants;
import java.awt.Component;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.*;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author mathias
 */
public class SharedDrawingUI extends javax.swing.JFrame {
    
    /**
     * action worker
     */
    public class UIWorker extends SwingWorker<Object, Action>{

   
        private BlockingQueue<Action> in_queue;
        private boolean connected;

        public UIWorker(){
            connected = true;
            in_queue = new LinkedBlockingQueue();
        }

        public void push(Action action)
        {
            try {
                in_queue.put(action);
            } catch (InterruptedException ex) {
                Logger.getLogger(UIWorker.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        @Override
        protected Object doInBackground() throws Exception {
            while(connected)
            {
                Action action = in_queue.take();
                publish(action);
            }
            return null;
        }

        @Override
        protected void process(List<Action> chunks) {
            for (Action action : chunks) {
                String type = action.getType();
                if (XmlConstants.welcome.equals(type))
                {
                    join();
                } else if (XmlConstants.joinWorkgroup.equals(type))
                {
                    addToUsersList(action.get(XmlConstants.emitterNickName));
                } else if (XmlConstants.leaveWorkgroup.equals(type))
                {
                    String nickName = action.get(XmlConstants.emitterNickName);
                    removeFromUserList(nickName);
                } else if (XmlConstants.chat.equals(type))
                {
                    String nickName = ConnexionManager.getInstance().
                            getNickName(action.get(XmlConstants.emitterId));
                    String text = action.get(XmlConstants.message);
                    jTextAreaChatBox.append(
                            "<"+nickName +">"+text);
                } else if (XmlConstants.createPage.equals(type))
                {
                    while(!Pages.getInstance().getWaitingPages().empty())
                    {          
                        Page page = Pages.getInstance().getWaitingPages().pop();
                        addToPageList(page.getName());
                        HiddenTabs.put(page.getName(), page);
                    }
                }
                else if (XmlConstants.openPage.equals(type))
                {
                    String selected = jTabbedPaneDrawingContainer.getTitleAt(
                                jTabbedPaneDrawingContainer.getSelectedIndex());
                    setUserList(selected);
                }
                else if (XmlConstants.closePage.equals(type))
                {
                    String selected = jTabbedPaneDrawingContainer.getTitleAt(
                                jTabbedPaneDrawingContainer.getSelectedIndex());
                    setUserList(selected);
                }
                else if (XmlConstants.connect.equals(type))
                {
                    jDialogConnectionManager.setVisible(false);
                    jMenuItemDisconnect.setEnabled(true);
                    jMenuItemJoin.setEnabled(true);
                    jMenuItemConnect.setEnabled(false);
                    jLabelStatusBar.setText("connected, I am " +
                            ConnexionManager.getInstance().getNickname());
                }
                else if (XmlConstants.connectRefused.equals(type))
                {
                    String msg = action.get(XmlConstants.message);
                    jLabelConnexionState.setText("Connexion Failure : " + msg);
                }
                else if (XmlConstants.error.equals(type))
                {
                    String message = action.get(XmlConstants.message);
                    JOptionPane.showMessageDialog(
                            SharedDrawingUI.getInstance(), 
                            message,
                            "ouch",
                            JOptionPane.ERROR_MESSAGE);
                }
                else {
                    System.out.println("not handled : " + type);
                }
            }
        }

        public void setConnected(boolean connected) {
            this.connected = connected;
        }
    
    }
    /**
     * Creates new form SharedDrawingUI
     */
    private Font fontNormal;
    private Font fontShow;
    private static SharedDrawingUI instance;
    private String colorToChange;
    private HashMap<String, Page> HiddenTabs;
    private static HashMap<String, Boolean> users;
    private UIWorker worker;
    
    private SharedDrawingUI() {
        fontNormal = new Font("Arial", Font.PLAIN, 12);
        fontShow = new Font("Arial", Font.BOLD, 14);
        HiddenTabs = new HashMap<String, Page>();
        users = new HashMap();
        initComponents();
        jListPageList.setModel(new DefaultListModel());
        jListUsersList.setModel(new DefaultListModel());
        addPrimitivePanels();
        worker = new UIWorker();
        
        ActionListener al_close = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if(!"newTab".equals(jTabbedPaneDrawingContainer.getSelectedComponent().getName()))
                {
                    if(jTabbedPaneDrawingContainer.getSelectedComponent() instanceof Page)
                        closePage(jTabbedPaneDrawingContainer.getSelectedIndex());
                    else
                    {
                        System.out.println("removing something that is not a page");
                        //jTabbedPaneDrawingContainer.remove(jTabbedPaneDrawingContainer.getSelectedComponent());
                    }
                        
                }
            }
        };
        
        ActionListener al_open = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                jDialogNewPage.setVisible(true);
                jDialogNewPage.setBounds(300, 200, WIDTH, WIDTH);
            }
        };
        
        KeyStroke ks_leave = KeyStroke.getKeyStroke(KeyEvent.VK_W,KeyEvent.CTRL_DOWN_MASK);
        KeyStroke ks_open = KeyStroke.getKeyStroke(KeyEvent.VK_T,KeyEvent.CTRL_DOWN_MASK);
        jTabbedPaneDrawingContainer.registerKeyboardAction(al_close, ks_leave, ICONIFIED);
        jTabbedPaneDrawingContainer.registerKeyboardAction(al_open, ks_open, ICONIFIED);
        //add undo and redo buttons
        URL path = getClass().getResource("/resources/undo.png");
        final JButton undoButton = new JButton(new ImageIcon(path));
        jToolBar1.add(undoButton);
        undoButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Component component = jTabbedPaneDrawingContainer.getSelectedComponent();
                if(component instanceof Page)
                {
                    Page page = (Page)component;
                    page.undo();
                }
            }
        });
        path = getClass().getResource("/resources/redo.png");
        final JButton redoButton = new JButton(new ImageIcon(path));
        jToolBar1.add(redoButton);
        redoButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Component component = jTabbedPaneDrawingContainer.getSelectedComponent();
                if(component instanceof Page)
                {
                    Page page = (Page)component;
                    page.redo();
                }
            }
        });
        addWindowListener(new WindowAdapter()
        {
            @Override
            public void windowClosing(WindowEvent e)
            {
                if(askLeave())
                {
                    disconnect();
                    System.exit(0);
                }
            }
        }); 
        
        pack();
        setVisible(true);
    }
    
    private void join()
    {
        jDialogJoinWorkgroup.setVisible(false);
        jMenuItemCloseCurrentPage.setEnabled(true);
        jMenuItemOpenNewPage.setEnabled(true);
        jMenuItemLeave.setEnabled(true);
        jMenuItemJoin.setEnabled(false);
        jMenuItemSave.setEnabled(true);
        jMenuItemSaveAll.setEnabled(true);
        jMenuItemImportFile.setEnabled(true);
        jTextSendChatBox.setEnabled(true);
        jButtonSendMessage.setEnabled(true);
        jLabelStatusBar.setText("connected, workgroup : " + 
                ConnexionManager.getInstance().getWorkgroupName() +
                ", I am " + 
                ConnexionManager.getInstance().getNickname());
    }
    
    private boolean leave()
    {
        boolean ret;

        ret = saveAll();

        if(ret)
        {
            for(int i = 0 ; i < jTabbedPaneDrawingContainer.getTabCount()-1; i++)
            {
                jTabbedPaneDrawingContainer.remove(i);
            }
            ConnexionManager.getInstance().leave();
            jTextAreaChatBox.setText("");
            jTextSendChatBox.setText("");
            jDialogJoinWorkgroupClear();
            HiddenTabs.clear();
            clearPages();
            jMenuItemCloseCurrentPage.setEnabled(false);
            jMenuItemOpenNewPage.setEnabled(false);
            jMenuItemLeave.setEnabled(false);
            jMenuItemJoin.setEnabled(true);
            jMenuItemSave.setEnabled(false);
            jMenuItemSaveAll.setEnabled(false);
            jMenuItemImportFile.setEnabled(false);
            jMenuItemExportPng.setEnabled(false);
            jTextSendChatBox.setEnabled(false);
            jButtonSendMessage.setEnabled(false);
            jLabelStatusBar.setText("connected");
        }
        return ret;
    }
    
    private boolean askLeave() {
        if(!ConnexionManager.getInstance().isConnected())
        {
            return true;
        }
        else
        {
            int n = JOptionPane.showConfirmDialog(
                this,
                "leave the workgroup ?",
                "leave",
                JOptionPane.YES_NO_OPTION);
            if(n == JOptionPane.YES_OPTION)
            {
                return leave();
            }
            return false;
        }
    }
    
    /**
     * This method is used to save any page as XML or PNG
     */
    public boolean saveAll()
    {
        boolean  ret;
        if(Pages.getInstance().getPages().isEmpty())
        {
            ret = true;
        }
        else
        {   
            ret = new SaveAllPanel(jTableSavePageList, jFileChooserOpenFile, this).run();
        }
        return ret;
    }
    
    private void disconnect()
    {
        ConnexionManager.getInstance().disconnect();
        jMenuItemDisconnect.setEnabled(false);
        jMenuItemConnect.setEnabled(true);
        jLabelStatusBar.setText("not connected");
    }
    
    UIWorker getWorker() {
        return worker;
    }
    
    public Page getHiddenTab(String title)
    {
        return HiddenTabs.get(title);
    }
    
    public void addHiddenTab(String title, Page HiddenTab)
    {
        HiddenTabs.put(title, HiddenTab);
    }
    
    public void removeFromHiddenTabs(String title)
    {
        HiddenTabs.remove(title);
    }
    
    /**
     * to get the instance of the GUI since it is a singleton
     * @return the GUI instance
     */
    public static SharedDrawingUI getInstance()
    {
        if(instance == null)
            instance = new SharedDrawingUI();
        
        return instance;
    }

    /**
     * to get the chat box
     * @return the chatBox, a JTextArea.
     */
    public static JTextArea getjTextAreaChatBox() {
        return jTextAreaChatBox;
    }

    /**
     * to get the text field of the chat box
     * @return a JTextPane, the user text field.
     */
    public static JTextPane getjTextSendChatBox() {
        return jTextSendChatBox;
    }

    private  void addPrimitivePanels()
    {
        
        //primitves
        JPanel primitives = new JPanel();
        primitives.setLayout(new GridLayout(0, 2));
        //vbox
        Box box = Box.createVerticalBox();
        jPanelPrimitives.add(box);
        box.add(primitives);
        box.add(Box.createVerticalGlue());
        URL path = getClass().getResource("/resources/Select.png");
        final JButton SelectButton = new JButton(new ImageIcon(path));
        primitives.add(SelectButton);
        SelectButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Pages.getInstance().setSelectionMode(true);
            }
        });

        ArrayList<Class> classes = Pages.getInstance().getFactory().getClasses();
        for(Class current : classes)
        {
            URL path2 = getClass().getResource("/resources/"+current.getSimpleName()+".png");
            if(path2 == null)
                path2 = getClass().getResource("/resources/Default.png");
            final JButton newButton = new JButton(new ImageIcon(path2));
            newButton.setName(current.getSimpleName());
            primitives.add(newButton);
            newButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    Pages.getInstance().setPrimitiveType(newButton.getName());
                    Pages.getInstance().setSelectionMode(false);
                }
            });
        }
    }
    
    public void closeDialogJoin() {
        jDialogJoinWorkgroup.setVisible(false);
        jLabelJoinWait.setText("");
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDialogAbout = new javax.swing.JDialog();
        jButtonAboutOk = new javax.swing.JButton();
        jPanelAboutInformation = new javax.swing.JPanel();
        jPanelAboutAuthors = new javax.swing.JPanel();
        jLabelAboutMickael = new javax.swing.JLabel();
        jLabelAboutMathias = new javax.swing.JLabel();
        jLabelAboutLeo = new javax.swing.JLabel();
        jLabelAboutClement = new javax.swing.JLabel();
        jDialogConnectionManager = new javax.swing.JDialog();
        jTextFieldHost = new javax.swing.JTextField();
        jTextFieldPort = new javax.swing.JTextField();
        jTextFieldNickName = new javax.swing.JTextField();
        jLabelHost = new javax.swing.JLabel();
        jLabelPort = new javax.swing.JLabel();
        jLabelNickName = new javax.swing.JLabel();
        jButtonConnectionConnect = new javax.swing.JButton();
        jButtonConnectionCancel = new javax.swing.JButton();
        jLabelConnexionState = new javax.swing.JLabel();
        jDialogConfirmDisconnection = new javax.swing.JDialog();
        jLabel1 = new javax.swing.JLabel();
        jButtonConfirmDisconnection = new javax.swing.JButton();
        jButtonCancelDisconnection = new javax.swing.JButton();
        jDialogOpenFile = new javax.swing.JDialog();
        jFileChooserOpenFile = new javax.swing.JFileChooser();
        jDialogJoinWorkgroup = new javax.swing.JDialog();
        jButtonJoinWorkgroup = new javax.swing.JButton();
        jButtonJoinWorkgroupCancel = new javax.swing.JButton();
        jLabelWorkgroupName = new javax.swing.JLabel();
        jLabelWorkgroupPassword = new javax.swing.JLabel();
        jTextFieldWorkgroupName = new javax.swing.JTextField();
        jTextFieldWorkgroupPassword = new javax.swing.JTextField();
        jLabelJoinWait = new java.awt.Label();
        jDialogSaveAll = new javax.swing.JDialog();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTableSavePageList = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jButtonSavePageListSave = new javax.swing.JButton();
        jButtonSavePageListCancel = new javax.swing.JButton();
        jDialogSelectColor = new javax.swing.JDialog();
        jColorChooserPalette = new javax.swing.JColorChooser();
        jButtonColorChooserOk = new javax.swing.JButton();
        jDialogTooManyDrawings = new javax.swing.JDialog();
        jLabelTooManyDrawings = new javax.swing.JLabel();
        jButtonCannotCreateDrawing = new javax.swing.JButton();
        jDialogNewPage = new javax.swing.JDialog();
        jTextFieldNewPageName = new javax.swing.JTextField();
        jLabelNewPageName = new javax.swing.JLabel();
        jButtonNewPageCreate = new javax.swing.JButton();
        jButtonNewPageCancel = new javax.swing.JButton();
        jToolBar1 = new javax.swing.JToolBar();
        jPanelBounding = new javax.swing.JPanel();
        jPanelChatContainer = new javax.swing.JPanel();
        jButtonSendMessage = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextAreaChatBox = new javax.swing.JTextArea();
        jScrollPane4 = new javax.swing.JScrollPane();
        jScrollPaneChatInput = new javax.swing.JScrollPane();
        jTextSendChatBox = new javax.swing.JTextPane();
        jScrollUserList = new javax.swing.JScrollPane();
        jListUsersList = new javax.swing.JList();
        jTabbedPaneDrawingContainer = new javax.swing.JTabbedPane();
        jPanelnewTab = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTextAreaWelcomeMessage = new javax.swing.JTextArea();
        jPanelParameters = new javax.swing.JPanel();
        jCheckBoxFill = new javax.swing.JCheckBox();
        jPanelPrimaryColor = new javax.swing.JPanel();
        jPanelSecondaryColor = new javax.swing.JPanel();
        jPanelPrimitiveWidth = new javax.swing.JPanel();
        jSliderPrimitiveWidth = new javax.swing.JSlider();
        jPanelColors = new javax.swing.JPanel();
        jPanelColorBlack = new javax.swing.JPanel();
        jPanelColorWhite = new javax.swing.JPanel();
        jPanelColorGrey = new javax.swing.JPanel();
        jPanelColorBrown = new javax.swing.JPanel();
        jPanelColorDarkBlue = new javax.swing.JPanel();
        jPanelColorGreen = new javax.swing.JPanel();
        jPanelColorCyan = new javax.swing.JPanel();
        jPanelColorMagenta = new javax.swing.JPanel();
        jPanelColorRed = new javax.swing.JPanel();
        jPanelColorYellow = new javax.swing.JPanel();
        jPanelColorPink = new javax.swing.JPanel();
        jPanelColorOrange = new javax.swing.JPanel();
        jPanelStatusBar = new javax.swing.JPanel();
        jLabelStatusBar = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListPageList = new javax.swing.JList();
        jScrollPane6 = new javax.swing.JScrollPane();
        jPanelPrimitives = new javax.swing.JPanel();
        jMenuBarMenuSet = new javax.swing.JMenuBar();
        jMenuFile = new javax.swing.JMenu();
        jMenuItemSave = new javax.swing.JMenuItem();
        jMenuItemSaveAll = new javax.swing.JMenuItem();
        jMenuItemExportPng = new javax.swing.JMenuItem();
        jMenuItemImportFile = new javax.swing.JMenuItem();
        jMenuItemQuit = new javax.swing.JMenuItem();
        jMenuEdit = new javax.swing.JMenu();
        jMenuItemCloseCurrentPage = new javax.swing.JMenuItem();
        jMenuItemOpenNewPage = new javax.swing.JMenuItem();
        jMenuServer = new javax.swing.JMenu();
        jMenuItemConnect = new javax.swing.JMenuItem();
        jMenuItemDisconnect = new javax.swing.JMenuItem();
        jMenuWorkgroup = new javax.swing.JMenu();
        jMenuItemJoin = new javax.swing.JMenuItem();
        jMenuItemLeave = new javax.swing.JMenuItem();
        jMenuHelp = new javax.swing.JMenu();
        jMenuItemAbout = new javax.swing.JMenuItem();

        jDialogAbout.setTitle("About");
        jDialogAbout.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jDialogAbout.setFocusCycleRoot(false);
        jDialogAbout.setMinimumSize(new java.awt.Dimension(398, 288));
        jDialogAbout.setResizable(false);

        jButtonAboutOk.setText("Ok");
        jButtonAboutOk.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonAboutOkMouseClicked(evt);
            }
        });

        jPanelAboutInformation.setBorder(javax.swing.BorderFactory.createTitledBorder("Information"));

        javax.swing.GroupLayout jPanelAboutInformationLayout = new javax.swing.GroupLayout(jPanelAboutInformation);
        jPanelAboutInformation.setLayout(jPanelAboutInformationLayout);
        jPanelAboutInformationLayout.setHorizontalGroup(
            jPanelAboutInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanelAboutInformationLayout.setVerticalGroup(
            jPanelAboutInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        jPanelAboutAuthors.setBorder(javax.swing.BorderFactory.createTitledBorder("Authors"));

        jLabelAboutMickael.setText("Mickaël Bosch");

        jLabelAboutMathias.setText("Mathias Brousset");

        jLabelAboutLeo.setText("Léo Tellier");

        jLabelAboutClement.setText("Clément Thomas-Ferron");

        javax.swing.GroupLayout jPanelAboutAuthorsLayout = new javax.swing.GroupLayout(jPanelAboutAuthors);
        jPanelAboutAuthors.setLayout(jPanelAboutAuthorsLayout);
        jPanelAboutAuthorsLayout.setHorizontalGroup(
            jPanelAboutAuthorsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelAboutAuthorsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelAboutAuthorsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelAboutAuthorsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabelAboutMickael, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabelAboutMathias, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                        .addComponent(jLabelAboutLeo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jLabelAboutClement))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelAboutAuthorsLayout.setVerticalGroup(
            jPanelAboutAuthorsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelAboutAuthorsLayout.createSequentialGroup()
                .addComponent(jLabelAboutMickael)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelAboutMathias)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelAboutLeo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabelAboutClement)
                .addContainerGap())
        );

        javax.swing.GroupLayout jDialogAboutLayout = new javax.swing.GroupLayout(jDialogAbout.getContentPane());
        jDialogAbout.getContentPane().setLayout(jDialogAboutLayout);
        jDialogAboutLayout.setHorizontalGroup(
            jDialogAboutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogAboutLayout.createSequentialGroup()
                .addGroup(jDialogAboutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jDialogAboutLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jDialogAboutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanelAboutInformation, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanelAboutAuthors, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jDialogAboutLayout.createSequentialGroup()
                        .addGap(133, 133, 133)
                        .addComponent(jButtonAboutOk, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 129, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jDialogAboutLayout.setVerticalGroup(
            jDialogAboutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDialogAboutLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelAboutInformation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelAboutAuthors, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButtonAboutOk)
                .addContainerGap())
        );

        jDialogConnectionManager.setTitle("Connection to server");
        jDialogConnectionManager.setMinimumSize(new java.awt.Dimension(270, 220));
        jDialogConnectionManager.setResizable(false);

        jTextFieldHost.setText("localhost");

        jTextFieldPort.setText("18000");

        jLabelHost.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelHost.setText("Host :");

        jLabelPort.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelPort.setText("Port :");

        jLabelNickName.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelNickName.setText("Nickname :");

        jButtonConnectionConnect.setText("Connect");
        jButtonConnectionConnect.setSelected(true);
        jButtonConnectionConnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConnectionConnectActionPerformed(evt);
            }
        });

        jButtonConnectionCancel.setText("Cancel");
        jButtonConnectionCancel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonConnectionCancelMouseClicked(evt);
            }
        });

        jLabelConnexionState.setText("not connected");

        javax.swing.GroupLayout jDialogConnectionManagerLayout = new javax.swing.GroupLayout(jDialogConnectionManager.getContentPane());
        jDialogConnectionManager.getContentPane().setLayout(jDialogConnectionManagerLayout);
        jDialogConnectionManagerLayout.setHorizontalGroup(
            jDialogConnectionManagerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogConnectionManagerLayout.createSequentialGroup()
                .addContainerGap(54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jDialogConnectionManagerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jDialogConnectionManagerLayout.createSequentialGroup()
                        .addGroup(jDialogConnectionManagerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabelNickName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(jDialogConnectionManagerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabelPort, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabelHost, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)))
                        .addGap(46, 46, 46)
                        .addGroup(jDialogConnectionManagerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jTextFieldHost, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
                            .addComponent(jTextFieldNickName)
                            .addComponent(jTextFieldPort))
                        .addContainerGap())
                    .addGroup(jDialogConnectionManagerLayout.createSequentialGroup()
                        .addGroup(jDialogConnectionManagerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabelConnexionState, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(jDialogConnectionManagerLayout.createSequentialGroup()
                                .addGap(0, 11, Short.MAX_VALUE)
                                .addComponent(jButtonConnectionCancel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonConnectionConnect)))
                        .addGap(58, 58, 58))))
        );
        jDialogConnectionManagerLayout.setVerticalGroup(
            jDialogConnectionManagerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogConnectionManagerLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jDialogConnectionManagerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldHost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelHost))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jDialogConnectionManagerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelPort))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jDialogConnectionManagerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldNickName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelNickName))
                .addGap(39, 39, 39)
                .addGroup(jDialogConnectionManagerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonConnectionConnect)
                    .addComponent(jButtonConnectionCancel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                .addComponent(jLabelConnexionState, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jDialogConfirmDisconnection.setTitle("Disconnect from server");
        jDialogConfirmDisconnection.setMinimumSize(new java.awt.Dimension(300, 60));
        jDialogConfirmDisconnection.setResizable(false);

        jLabel1.setText("Do you really want to disconnect from the server ?");

        jButtonConfirmDisconnection.setText("Disconnect");
        jButtonConfirmDisconnection.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonConfirmDisconnectionMouseClicked(evt);
            }
        });

        jButtonCancelDisconnection.setText("Cancel");
        jButtonCancelDisconnection.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonCancelDisconnectionMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jDialogConfirmDisconnectionLayout = new javax.swing.GroupLayout(jDialogConfirmDisconnection.getContentPane());
        jDialogConfirmDisconnection.getContentPane().setLayout(jDialogConfirmDisconnectionLayout);
        jDialogConfirmDisconnectionLayout.setHorizontalGroup(
            jDialogConfirmDisconnectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogConfirmDisconnectionLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonCancelDisconnection, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jButtonConfirmDisconnection)
                .addGap(64, 64, 64))
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jDialogConfirmDisconnectionLayout.setVerticalGroup(
            jDialogConfirmDisconnectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogConfirmDisconnectionLayout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jDialogConfirmDisconnectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCancelDisconnection)
                    .addComponent(jButtonConfirmDisconnection))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jDialogOpenFile.setMinimumSize(new java.awt.Dimension(626, 419));
        jDialogOpenFile.setResizable(false);

        jFileChooserOpenFile.setMultiSelectionEnabled(true);

        javax.swing.GroupLayout jDialogOpenFileLayout = new javax.swing.GroupLayout(jDialogOpenFile.getContentPane());
        jDialogOpenFile.getContentPane().setLayout(jDialogOpenFileLayout);
        jDialogOpenFileLayout.setHorizontalGroup(
            jDialogOpenFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDialogOpenFileLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jFileChooserOpenFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jDialogOpenFileLayout.setVerticalGroup(
            jDialogOpenFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDialogOpenFileLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jFileChooserOpenFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jDialogJoinWorkgroup.setTitle("Join a workgroup");
        jDialogJoinWorkgroup.setMinimumSize(new java.awt.Dimension(306, 151));
        jDialogJoinWorkgroup.setResizable(false);

        jButtonJoinWorkgroup.setText("Join");
        jButtonJoinWorkgroup.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonJoinWorkgroupMouseClicked(evt);
            }
        });

        jButtonJoinWorkgroupCancel.setText("Cancel");
        jButtonJoinWorkgroupCancel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonJoinWorkgroupCancelMouseClicked(evt);
            }
        });

        jLabelWorkgroupName.setText("Workgroup name :");

        jLabelWorkgroupPassword.setText("password :");

        javax.swing.GroupLayout jDialogJoinWorkgroupLayout = new javax.swing.GroupLayout(jDialogJoinWorkgroup.getContentPane());
        jDialogJoinWorkgroup.getContentPane().setLayout(jDialogJoinWorkgroupLayout);
        jDialogJoinWorkgroupLayout.setHorizontalGroup(
            jDialogJoinWorkgroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogJoinWorkgroupLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jDialogJoinWorkgroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDialogJoinWorkgroupLayout.createSequentialGroup()
                        .addGap(0, 46, Short.MAX_VALUE)
                        .addGroup(jDialogJoinWorkgroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabelWorkgroupName)
                            .addComponent(jLabelWorkgroupPassword))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jDialogJoinWorkgroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldWorkgroupName)
                            .addComponent(jTextFieldWorkgroupPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE))
                        .addContainerGap(60, Short.MAX_VALUE))
                    .addGroup(jDialogJoinWorkgroupLayout.createSequentialGroup()
                        .addComponent(jLabelJoinWait, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(22, 22, 22)
                        .addComponent(jButtonJoinWorkgroupCancel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonJoinWorkgroup, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        jDialogJoinWorkgroupLayout.setVerticalGroup(
            jDialogJoinWorkgroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDialogJoinWorkgroupLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jDialogJoinWorkgroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelWorkgroupName)
                    .addComponent(jTextFieldWorkgroupName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jDialogJoinWorkgroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelWorkgroupPassword)
                    .addComponent(jTextFieldWorkgroupPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                .addGroup(jDialogJoinWorkgroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelJoinWait, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jDialogJoinWorkgroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButtonJoinWorkgroupCancel)
                        .addComponent(jButtonJoinWorkgroup)))
                .addGap(41, 41, 41))
        );

        jDialogSaveAll.setMinimumSize(new java.awt.Dimension(450, 260));
        jDialogSaveAll.setResizable(false);

        jTableSavePageList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Page name", "Export to XML", "Export to PNG"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Boolean.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jTableSavePageList);
        jTableSavePageList.getColumnModel().getColumn(0).setResizable(false);
        jTableSavePageList.getColumnModel().getColumn(1).setResizable(false);
        jTableSavePageList.getColumnModel().getColumn(2).setResizable(false);

        jLabel2.setText("Select XML to re-use the page later. Select PNG to save the page as an image.");

        jButtonSavePageListSave.setText("Save");
        jButtonSavePageListSave.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonSavePageListSaveMouseClicked(evt);
            }
        });

        jButtonSavePageListCancel.setText("Cancel");
        jButtonSavePageListCancel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonSavePageListCancelMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jDialogSaveAllLayout = new javax.swing.GroupLayout(jDialogSaveAll.getContentPane());
        jDialogSaveAll.getContentPane().setLayout(jDialogSaveAllLayout);
        jDialogSaveAllLayout.setHorizontalGroup(
            jDialogSaveAllLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogSaveAllLayout.createSequentialGroup()
                .addContainerGap(15, Short.MAX_VALUE)
                .addGroup(jDialogSaveAllLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 428, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 428, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDialogSaveAllLayout.createSequentialGroup()
                        .addComponent(jButtonSavePageListCancel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonSavePageListSave)))
                .addContainerGap())
        );
        jDialogSaveAllLayout.setVerticalGroup(
            jDialogSaveAllLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogSaveAllLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jDialogSaveAllLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonSavePageListSave)
                    .addComponent(jButtonSavePageListCancel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jDialogSelectColor.setTitle("Color selection");
        jDialogSelectColor.setMinimumSize(new java.awt.Dimension(450, 450));
        jDialogSelectColor.setResizable(false);

        jColorChooserPalette.setMinimumSize(new java.awt.Dimension(429, 347));

        jButtonColorChooserOk.setText("OK");
        jButtonColorChooserOk.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonColorChooserOkMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jDialogSelectColorLayout = new javax.swing.GroupLayout(jDialogSelectColor.getContentPane());
        jDialogSelectColor.getContentPane().setLayout(jDialogSelectColorLayout);
        jDialogSelectColorLayout.setHorizontalGroup(
            jDialogSelectColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogSelectColorLayout.createSequentialGroup()
                .addGroup(jDialogSelectColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jColorChooserPalette, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonColorChooserOk, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jDialogSelectColorLayout.setVerticalGroup(
            jDialogSelectColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogSelectColorLayout.createSequentialGroup()
                .addComponent(jColorChooserPalette, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButtonColorChooserOk)
                .addContainerGap(92, Short.MAX_VALUE))
        );

        jDialogTooManyDrawings.setTitle("Error");
        jDialogTooManyDrawings.setMinimumSize(new java.awt.Dimension(500, 130));

        jLabelTooManyDrawings.setText("Error : could not create a new drawing(Too many drawings are currently edited)");

        jButtonCannotCreateDrawing.setText("OK");
        jButtonCannotCreateDrawing.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCannotCreateDrawingActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDialogTooManyDrawingsLayout = new javax.swing.GroupLayout(jDialogTooManyDrawings.getContentPane());
        jDialogTooManyDrawings.getContentPane().setLayout(jDialogTooManyDrawingsLayout);
        jDialogTooManyDrawingsLayout.setHorizontalGroup(
            jDialogTooManyDrawingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogTooManyDrawingsLayout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addComponent(jLabelTooManyDrawings)
                .addContainerGap(45, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDialogTooManyDrawingsLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButtonCannotCreateDrawing, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(168, 168, 168))
        );
        jDialogTooManyDrawingsLayout.setVerticalGroup(
            jDialogTooManyDrawingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogTooManyDrawingsLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabelTooManyDrawings)
                .addGap(18, 18, 18)
                .addComponent(jButtonCannotCreateDrawing)
                .addContainerGap(30, Short.MAX_VALUE))
        );

        jDialogNewPage.setMinimumSize(new java.awt.Dimension(275, 120));

        jLabelNewPageName.setText("Page name");

        jButtonNewPageCreate.setText("Ok");
        jButtonNewPageCreate.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonNewPageCreateMouseClicked(evt);
            }
        });

        jButtonNewPageCancel.setText("Cancel");
        jButtonNewPageCancel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonNewPageCancelMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jDialogNewPageLayout = new javax.swing.GroupLayout(jDialogNewPage.getContentPane());
        jDialogNewPage.getContentPane().setLayout(jDialogNewPageLayout);
        jDialogNewPageLayout.setHorizontalGroup(
            jDialogNewPageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDialogNewPageLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jDialogNewPageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelNewPageName)
                    .addComponent(jButtonNewPageCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addGroup(jDialogNewPageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextFieldNewPageName, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonNewPageCreate, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(122, 122, 122))
        );
        jDialogNewPageLayout.setVerticalGroup(
            jDialogNewPageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialogNewPageLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jDialogNewPageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldNewPageName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelNewPageName))
                .addGap(18, 18, 18)
                .addGroup(jDialogNewPageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonNewPageCreate)
                    .addComponent(jButtonNewPageCancel))
                .addContainerGap(29, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Shared Drawing");
        setMaximumSize(null);
        setMinimumSize(new java.awt.Dimension(1050, 750));
        setPreferredSize(new java.awt.Dimension(1050, 750));

        jToolBar1.setRollover(true);

        jPanelChatContainer.setBorder(javax.swing.BorderFactory.createTitledBorder("Chat"));
        jPanelChatContainer.setMaximumSize(new java.awt.Dimension(245, 310));
        jPanelChatContainer.setMinimumSize(new java.awt.Dimension(245, 310));

        jButtonSendMessage.setText("Send Message");
        jButtonSendMessage.setEnabled(false);
        jButtonSendMessage.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonSendMessageMouseClicked(evt);
            }
        });

        jTextAreaChatBox.setColumns(20);
        jTextAreaChatBox.setEditable(false);
        jTextAreaChatBox.setRows(5);
        jTextAreaChatBox.setMaximumSize(null);
        jTextAreaChatBox.setMinimumSize(null);
        jTextAreaChatBox.setPreferredSize(null);
        jScrollPane3.setViewportView(jTextAreaChatBox);

        jTextSendChatBox.setEnabled(false);
        jTextSendChatBox.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextSendChatBoxKeyTyped(evt);
            }
        });
        jScrollPaneChatInput.setViewportView(jTextSendChatBox);

        jScrollPane4.setViewportView(jScrollPaneChatInput);

        javax.swing.GroupLayout jPanelChatContainerLayout = new javax.swing.GroupLayout(jPanelChatContainer);
        jPanelChatContainer.setLayout(jPanelChatContainerLayout);
        jPanelChatContainerLayout.setHorizontalGroup(
            jPanelChatContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelChatContainerLayout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addComponent(jButtonSendMessage)
                .addContainerGap())
            .addComponent(jScrollPane3)
            .addComponent(jScrollPane4)
        );
        jPanelChatContainerLayout.setVerticalGroup(
            jPanelChatContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelChatContainerLayout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addComponent(jButtonSendMessage))
        );

        jScrollUserList.setBorder(javax.swing.BorderFactory.createTitledBorder("Users"));
        jScrollUserList.setEnabled(false);
        jScrollUserList.setMaximumSize(new java.awt.Dimension(245, 151));
        jScrollUserList.setMinimumSize(new java.awt.Dimension(245, 151));
        jScrollUserList.setPreferredSize(new java.awt.Dimension(245, 151));

        jListUsersList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollUserList.setViewportView(jListUsersList);

        jTabbedPaneDrawingContainer.setBackground(java.awt.Color.white);
        jTabbedPaneDrawingContainer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTabbedPaneDrawingContainerMouseClicked(evt);
            }
        });
        jTabbedPaneDrawingContainer.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                jTabbedPaneDrawingContainerComponentShown(evt);
            }
        });

        jPanelnewTab.setName("newTab");
        jPanelnewTab.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                jPanelnewTabComponentShown(evt);
            }
        });

        jTextAreaWelcomeMessage.setBackground(new java.awt.Color(255, 51, 51));
        jTextAreaWelcomeMessage.setColumns(20);
        jTextAreaWelcomeMessage.setEditable(false);
        jTextAreaWelcomeMessage.setFont(new java.awt.Font("MV Boli", 0, 13)); // NOI18N
        jTextAreaWelcomeMessage.setRows(5);
        jTextAreaWelcomeMessage.setText("Welcome !\n\n1  - To start using the software, first connect to a server!\n2  - Then create your own workgroup, or join a existing one!\n3  - You can start drawing, and chatting with your contacts.\n4  - At the end you can save your work by using the File\n     menu.\n\n\nMore information on :\nhttp://code.google.com/p/shared-drawing/");
        jScrollPane5.setViewportView(jTextAreaWelcomeMessage);

        javax.swing.GroupLayout jPanelnewTabLayout = new javax.swing.GroupLayout(jPanelnewTab);
        jPanelnewTab.setLayout(jPanelnewTabLayout);
        jPanelnewTabLayout.setHorizontalGroup(
            jPanelnewTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
        );
        jPanelnewTabLayout.setVerticalGroup(
            jPanelnewTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 581, Short.MAX_VALUE)
        );

        jTabbedPaneDrawingContainer.addTab("", new javax.swing.ImageIcon(getClass().getResource("/resources/newTab.png")), jPanelnewTab, "Create a new drawing page"); // NOI18N

        jPanelParameters.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters"));

        jCheckBoxFill.setText("Fill primitive");
        jCheckBoxFill.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jCheckBoxFillStateChanged(evt);
            }
        });

        jPanelPrimaryColor.setBackground(new java.awt.Color(0, 0, 0));
        jPanelPrimaryColor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanelPrimaryColor.setForeground(java.awt.Color.white);
        jPanelPrimaryColor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelPrimaryColorMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelPrimaryColorLayout = new javax.swing.GroupLayout(jPanelPrimaryColor);
        jPanelPrimaryColor.setLayout(jPanelPrimaryColorLayout);
        jPanelPrimaryColorLayout.setHorizontalGroup(
            jPanelPrimaryColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );
        jPanelPrimaryColorLayout.setVerticalGroup(
            jPanelPrimaryColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jPanelSecondaryColor.setBackground(new java.awt.Color(255, 255, 255));
        jPanelSecondaryColor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanelSecondaryColor.setForeground(new java.awt.Color(115, 13, 13));
        jPanelSecondaryColor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelSecondaryColorMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelSecondaryColorLayout = new javax.swing.GroupLayout(jPanelSecondaryColor);
        jPanelSecondaryColor.setLayout(jPanelSecondaryColorLayout);
        jPanelSecondaryColorLayout.setHorizontalGroup(
            jPanelSecondaryColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );
        jPanelSecondaryColorLayout.setVerticalGroup(
            jPanelSecondaryColorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jPanelPrimitiveWidth.setBorder(javax.swing.BorderFactory.createTitledBorder("Primitive width"));

        jSliderPrimitiveWidth.setMaximum(10);
        jSliderPrimitiveWidth.setMinimum(1);
        jSliderPrimitiveWidth.setValue(1);
        jSliderPrimitiveWidth.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jSliderPrimitiveWidthMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanelPrimitiveWidthLayout = new javax.swing.GroupLayout(jPanelPrimitiveWidth);
        jPanelPrimitiveWidth.setLayout(jPanelPrimitiveWidthLayout);
        jPanelPrimitiveWidthLayout.setHorizontalGroup(
            jPanelPrimitiveWidthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSliderPrimitiveWidth, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
        );
        jPanelPrimitiveWidthLayout.setVerticalGroup(
            jPanelPrimitiveWidthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelPrimitiveWidthLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jSliderPrimitiveWidth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout jPanelParametersLayout = new javax.swing.GroupLayout(jPanelParameters);
        jPanelParameters.setLayout(jPanelParametersLayout);
        jPanelParametersLayout.setHorizontalGroup(
            jPanelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelParametersLayout.createSequentialGroup()
                .addGroup(jPanelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelParametersLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jCheckBoxFill, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanelParametersLayout.createSequentialGroup()
                        .addGroup(jPanelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanelPrimitiveWidth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanelParametersLayout.createSequentialGroup()
                                .addGap(44, 44, 44)
                                .addComponent(jPanelPrimaryColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jPanelSecondaryColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 13, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanelParametersLayout.setVerticalGroup(
            jPanelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelParametersLayout.createSequentialGroup()
                .addComponent(jCheckBoxFill)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelPrimitiveWidth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelPrimaryColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelSecondaryColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelColors.setBorder(javax.swing.BorderFactory.createTitledBorder("Colors"));

        jPanelColorBlack.setBackground(java.awt.Color.black);
        jPanelColorBlack.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelColorBlackMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelColorBlackLayout = new javax.swing.GroupLayout(jPanelColorBlack);
        jPanelColorBlack.setLayout(jPanelColorBlackLayout);
        jPanelColorBlackLayout.setHorizontalGroup(
            jPanelColorBlackLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );
        jPanelColorBlackLayout.setVerticalGroup(
            jPanelColorBlackLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jPanelColorWhite.setBackground(java.awt.Color.white);
        jPanelColorWhite.setForeground(java.awt.Color.white);
        jPanelColorWhite.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelColorWhiteMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelColorWhiteLayout = new javax.swing.GroupLayout(jPanelColorWhite);
        jPanelColorWhite.setLayout(jPanelColorWhiteLayout);
        jPanelColorWhiteLayout.setHorizontalGroup(
            jPanelColorWhiteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );
        jPanelColorWhiteLayout.setVerticalGroup(
            jPanelColorWhiteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jPanelColorGrey.setBackground(java.awt.Color.gray);
        jPanelColorGrey.setForeground(java.awt.Color.gray);
        jPanelColorGrey.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelColorGreyMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelColorGreyLayout = new javax.swing.GroupLayout(jPanelColorGrey);
        jPanelColorGrey.setLayout(jPanelColorGreyLayout);
        jPanelColorGreyLayout.setHorizontalGroup(
            jPanelColorGreyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );
        jPanelColorGreyLayout.setVerticalGroup(
            jPanelColorGreyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jPanelColorBrown.setBackground(new java.awt.Color(66, 0, 0));
        jPanelColorBrown.setForeground(new java.awt.Color(115, 13, 13));
        jPanelColorBrown.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelColorBrownMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelColorBrownLayout = new javax.swing.GroupLayout(jPanelColorBrown);
        jPanelColorBrown.setLayout(jPanelColorBrownLayout);
        jPanelColorBrownLayout.setHorizontalGroup(
            jPanelColorBrownLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );
        jPanelColorBrownLayout.setVerticalGroup(
            jPanelColorBrownLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jPanelColorDarkBlue.setBackground(java.awt.Color.blue);
        jPanelColorDarkBlue.setForeground(java.awt.Color.blue);
        jPanelColorDarkBlue.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelColorDarkBlueMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelColorDarkBlueLayout = new javax.swing.GroupLayout(jPanelColorDarkBlue);
        jPanelColorDarkBlue.setLayout(jPanelColorDarkBlueLayout);
        jPanelColorDarkBlueLayout.setHorizontalGroup(
            jPanelColorDarkBlueLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );
        jPanelColorDarkBlueLayout.setVerticalGroup(
            jPanelColorDarkBlueLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jPanelColorGreen.setBackground(java.awt.Color.green);
        jPanelColorGreen.setForeground(java.awt.Color.green);
        jPanelColorGreen.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelColorGreenMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelColorGreenLayout = new javax.swing.GroupLayout(jPanelColorGreen);
        jPanelColorGreen.setLayout(jPanelColorGreenLayout);
        jPanelColorGreenLayout.setHorizontalGroup(
            jPanelColorGreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );
        jPanelColorGreenLayout.setVerticalGroup(
            jPanelColorGreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jPanelColorCyan.setBackground(java.awt.Color.cyan);
        jPanelColorCyan.setForeground(java.awt.Color.cyan);
        jPanelColorCyan.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelColorCyanMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelColorCyanLayout = new javax.swing.GroupLayout(jPanelColorCyan);
        jPanelColorCyan.setLayout(jPanelColorCyanLayout);
        jPanelColorCyanLayout.setHorizontalGroup(
            jPanelColorCyanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );
        jPanelColorCyanLayout.setVerticalGroup(
            jPanelColorCyanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jPanelColorMagenta.setBackground(java.awt.Color.magenta);
        jPanelColorMagenta.setForeground(java.awt.Color.magenta);
        jPanelColorMagenta.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelColorMagentaMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelColorMagentaLayout = new javax.swing.GroupLayout(jPanelColorMagenta);
        jPanelColorMagenta.setLayout(jPanelColorMagentaLayout);
        jPanelColorMagentaLayout.setHorizontalGroup(
            jPanelColorMagentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );
        jPanelColorMagentaLayout.setVerticalGroup(
            jPanelColorMagentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jPanelColorRed.setBackground(java.awt.Color.red);
        jPanelColorRed.setForeground(java.awt.Color.red);
        jPanelColorRed.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelColorRedMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelColorRedLayout = new javax.swing.GroupLayout(jPanelColorRed);
        jPanelColorRed.setLayout(jPanelColorRedLayout);
        jPanelColorRedLayout.setHorizontalGroup(
            jPanelColorRedLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );
        jPanelColorRedLayout.setVerticalGroup(
            jPanelColorRedLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jPanelColorYellow.setBackground(java.awt.Color.yellow);
        jPanelColorYellow.setForeground(java.awt.Color.yellow);
        jPanelColorYellow.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelColorYellowMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelColorYellowLayout = new javax.swing.GroupLayout(jPanelColorYellow);
        jPanelColorYellow.setLayout(jPanelColorYellowLayout);
        jPanelColorYellowLayout.setHorizontalGroup(
            jPanelColorYellowLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );
        jPanelColorYellowLayout.setVerticalGroup(
            jPanelColorYellowLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jPanelColorPink.setBackground(java.awt.Color.pink);
        jPanelColorPink.setForeground(java.awt.Color.pink);
        jPanelColorPink.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelColorPinkMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelColorPinkLayout = new javax.swing.GroupLayout(jPanelColorPink);
        jPanelColorPink.setLayout(jPanelColorPinkLayout);
        jPanelColorPinkLayout.setHorizontalGroup(
            jPanelColorPinkLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );
        jPanelColorPinkLayout.setVerticalGroup(
            jPanelColorPinkLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jPanelColorOrange.setBackground(java.awt.Color.orange);
        jPanelColorOrange.setForeground(java.awt.Color.orange);
        jPanelColorOrange.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelColorOrangeMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelColorOrangeLayout = new javax.swing.GroupLayout(jPanelColorOrange);
        jPanelColorOrange.setLayout(jPanelColorOrangeLayout);
        jPanelColorOrangeLayout.setHorizontalGroup(
            jPanelColorOrangeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );
        jPanelColorOrangeLayout.setVerticalGroup(
            jPanelColorOrangeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanelColorsLayout = new javax.swing.GroupLayout(jPanelColors);
        jPanelColors.setLayout(jPanelColorsLayout);
        jPanelColorsLayout.setHorizontalGroup(
            jPanelColorsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelColorsLayout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanelColorsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelColorsLayout.createSequentialGroup()
                        .addComponent(jPanelColorWhite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelColorBrown, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelColorGrey, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelColorBlack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelColorsLayout.createSequentialGroup()
                        .addComponent(jPanelColorOrange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelColorYellow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelColorCyan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelColorDarkBlue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelColorsLayout.createSequentialGroup()
                        .addComponent(jPanelColorPink, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelColorRed, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelColorMagenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelColorGreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelColorsLayout.setVerticalGroup(
            jPanelColorsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelColorsLayout.createSequentialGroup()
                .addGroup(jPanelColorsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelColorBlack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelColorGrey, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelColorBrown, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelColorWhite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelColorsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanelColorsLayout.createSequentialGroup()
                        .addComponent(jPanelColorYellow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanelColorRed, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelColorsLayout.createSequentialGroup()
                        .addComponent(jPanelColorDarkBlue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelColorGreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelColorsLayout.createSequentialGroup()
                        .addComponent(jPanelColorCyan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanelColorMagenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelColorsLayout.createSequentialGroup()
                        .addComponent(jPanelColorOrange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanelColorPink, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabelStatusBar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabelStatusBar.setText("not connected");

        javax.swing.GroupLayout jPanelStatusBarLayout = new javax.swing.GroupLayout(jPanelStatusBar);
        jPanelStatusBar.setLayout(jPanelStatusBarLayout);
        jPanelStatusBarLayout.setHorizontalGroup(
            jPanelStatusBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
            .addGroup(jPanelStatusBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelStatusBarLayout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jLabelStatusBar)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );
        jPanelStatusBarLayout.setVerticalGroup(
            jPanelStatusBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 19, Short.MAX_VALUE)
            .addGroup(jPanelStatusBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelStatusBarLayout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jLabelStatusBar)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );

        jListPageList.setBorder(javax.swing.BorderFactory.createTitledBorder("Pages list"));
        jListPageList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jListPageList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jListPageListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jListPageList);

        jPanelPrimitives.setBorder(javax.swing.BorderFactory.createTitledBorder("Primitives"));
        jPanelPrimitives.setMaximumSize(null);
        jPanelPrimitives.setLayout(new java.awt.GridLayout(1, 0));
        jScrollPane6.setViewportView(jPanelPrimitives);

        javax.swing.GroupLayout jPanelBoundingLayout = new javax.swing.GroupLayout(jPanelBounding);
        jPanelBounding.setLayout(jPanelBoundingLayout);
        jPanelBoundingLayout.setHorizontalGroup(
            jPanelBoundingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelStatusBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanelBoundingLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanelBoundingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane6)
                    .addComponent(jPanelParameters, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelColors, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPaneDrawingContainer, javax.swing.GroupLayout.PREFERRED_SIZE, 549, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelBoundingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollUserList, javax.swing.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
                    .addComponent(jScrollPane1)
                    .addComponent(jPanelChatContainer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        jPanelBoundingLayout.setVerticalGroup(
            jPanelBoundingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBoundingLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanelBoundingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelBoundingLayout.createSequentialGroup()
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 349, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelParameters, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelColors, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jTabbedPaneDrawingContainer, javax.swing.GroupLayout.PREFERRED_SIZE, 608, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanelBoundingLayout.createSequentialGroup()
                        .addComponent(jScrollUserList, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelChatContainer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanelStatusBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jMenuFile.setText("File");

        jMenuItemSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemSave.setText("Save");
        jMenuItemSave.setEnabled(false);
        jMenuItemSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSaveActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuItemSave);

        jMenuItemSaveAll.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemSaveAll.setText("Save all");
        jMenuItemSaveAll.setEnabled(false);
        jMenuItemSaveAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSaveAllActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuItemSaveAll);

        jMenuItemExportPng.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemExportPng.setText("export as png");
        jMenuItemExportPng.setEnabled(false);
        jMenuItemExportPng.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemExportPngActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuItemExportPng);

        jMenuItemImportFile.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemImportFile.setText("import file");
        jMenuItemImportFile.setEnabled(false);
        jMenuItemImportFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemImportFileActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuItemImportFile);

        jMenuItemQuit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemQuit.setText("Quit");
        jMenuItemQuit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemQuitActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuItemQuit);

        jMenuBarMenuSet.add(jMenuFile);

        jMenuEdit.setText("Edit");

        jMenuItemCloseCurrentPage.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemCloseCurrentPage.setText("Close current page");
        jMenuItemCloseCurrentPage.setEnabled(false);
        jMenuItemCloseCurrentPage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemCloseCurrentPageActionPerformed(evt);
            }
        });
        jMenuEdit.add(jMenuItemCloseCurrentPage);

        jMenuItemOpenNewPage.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemOpenNewPage.setText("Open new Page");
        jMenuItemOpenNewPage.setEnabled(false);
        jMenuItemOpenNewPage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemOpenNewPageActionPerformed(evt);
            }
        });
        jMenuEdit.add(jMenuItemOpenNewPage);

        jMenuBarMenuSet.add(jMenuEdit);

        jMenuServer.setText("Server");

        jMenuItemConnect.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_K, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemConnect.setText("Connect");
        jMenuItemConnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemConnectActionPerformed(evt);
            }
        });
        jMenuServer.add(jMenuItemConnect);

        jMenuItemDisconnect.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_K, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemDisconnect.setText("Disconnect");
        jMenuItemDisconnect.setEnabled(false);
        jMenuItemDisconnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemDisconnectActionPerformed(evt);
            }
        });
        jMenuServer.add(jMenuItemDisconnect);

        jMenuBarMenuSet.add(jMenuServer);

        jMenuWorkgroup.setText("Workgroup");

        jMenuItemJoin.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_J, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemJoin.setText("Join");
        jMenuItemJoin.setEnabled(false);
        jMenuItemJoin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemJoinActionPerformed(evt);
            }
        });
        jMenuWorkgroup.add(jMenuItemJoin);

        jMenuItemLeave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_J, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemLeave.setText("Leave");
        jMenuItemLeave.setEnabled(false);
        jMenuItemLeave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemLeaveActionPerformed(evt);
            }
        });
        jMenuWorkgroup.add(jMenuItemLeave);

        jMenuBarMenuSet.add(jMenuWorkgroup);

        jMenuHelp.setText("?");

        jMenuItemAbout.setText("About");
        jMenuItemAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemAboutActionPerformed(evt);
            }
        });
        jMenuHelp.add(jMenuItemAbout);

        jMenuBarMenuSet.add(jMenuHelp);

        setJMenuBar(jMenuBarMenuSet);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanelBounding, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelBounding, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItemLeaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemLeaveActionPerformed
        askLeave();
    }//GEN-LAST:event_jMenuItemLeaveActionPerformed

    private void jPanelPrimaryColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelPrimaryColorMouseClicked
        if(evt.getClickCount() == 2)
        {
            jDialogSelectColor.setVisible(true);
            colorToChange = "primary";
            jDialogSelectColor.setBounds(300, 200, WIDTH, WIDTH);
        }
    }//GEN-LAST:event_jPanelPrimaryColorMouseClicked

    private void jPanelSecondaryColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelSecondaryColorMouseClicked
        if(evt.getClickCount() == 2)
        {
            jDialogSelectColor.setVisible(true);
            colorToChange = "secondary";
            jDialogSelectColor.setBounds(300, 200, WIDTH, WIDTH);
        }
    }//GEN-LAST:event_jPanelSecondaryColorMouseClicked
    /*
     * COLOR PALETTE HERE
     */
    private void jPanelColorWhiteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelColorWhiteMouseClicked
        
        if(evt.getButton() == MouseEvent.BUTTON1)
        {
            jPanelPrimaryColor.setBackground(jPanelColorWhite.getBackground());
            Pages.getInstance().setBorderColorSelected(jPanelColorWhite.getBackground());
        }
        if(evt.getButton() == MouseEvent.BUTTON3)
        {
            jPanelSecondaryColor.setBackground(jPanelColorWhite.getBackground());
            Pages.getInstance().setColorSelected(jPanelColorWhite.getBackground());
        }
    }//GEN-LAST:event_jPanelColorWhiteMouseClicked

    private void jPanelColorBrownMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelColorBrownMouseClicked
        
        if(evt.getButton() == MouseEvent.BUTTON1)
        {
            jPanelPrimaryColor.setBackground(jPanelColorBrown.getBackground());
            Pages.getInstance().setBorderColorSelected(jPanelColorBrown.getBackground());
        }
        if(evt.getButton() == MouseEvent.BUTTON3)
        {
            jPanelSecondaryColor.setBackground(jPanelColorBrown.getBackground());
        }    Pages.getInstance().setColorSelected(jPanelColorBrown.getBackground());
    }//GEN-LAST:event_jPanelColorBrownMouseClicked

    private void jPanelColorGreyMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelColorGreyMouseClicked
        
        if(evt.getButton() == MouseEvent.BUTTON1)
        {
            jPanelPrimaryColor.setBackground(jPanelColorGrey.getBackground());
            Pages.getInstance().setBorderColorSelected(jPanelColorGrey.getBackground());
        }
        if(evt.getButton() == MouseEvent.BUTTON3)
        {
            jPanelSecondaryColor.setBackground(jPanelColorGrey.getBackground());
            Pages.getInstance().setColorSelected(jPanelColorGrey.getBackground());
        }
    }//GEN-LAST:event_jPanelColorGreyMouseClicked

    private void jPanelColorBlackMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelColorBlackMouseClicked
        
        if(evt.getButton() == MouseEvent.BUTTON1)
        {
            jPanelPrimaryColor.setBackground(jPanelColorBlack.getBackground());
            Pages.getInstance().setBorderColorSelected(jPanelColorBlack.getBackground());
        }
        if(evt.getButton() == MouseEvent.BUTTON3)
        {
            jPanelSecondaryColor.setBackground(jPanelColorBlack.getBackground());
            Pages.getInstance().setColorSelected(jPanelColorBlack.getBackground());
        }
    }//GEN-LAST:event_jPanelColorBlackMouseClicked

    private void jPanelColorOrangeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelColorOrangeMouseClicked
        
        if(evt.getButton() == MouseEvent.BUTTON1)
        {
            jPanelPrimaryColor.setBackground(jPanelColorOrange.getBackground());
            Pages.getInstance().setBorderColorSelected(jPanelColorOrange.getBackground());
        }
        if(evt.getButton() == MouseEvent.BUTTON3)
        {
            jPanelSecondaryColor.setBackground(jPanelColorOrange.getBackground());
            Pages.getInstance().setColorSelected(jPanelColorOrange.getBackground());
        }
    }//GEN-LAST:event_jPanelColorOrangeMouseClicked

    private void jPanelColorYellowMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelColorYellowMouseClicked
        
        if(evt.getButton() == MouseEvent.BUTTON1)
        {
            jPanelPrimaryColor.setBackground(jPanelColorYellow.getBackground());
            Pages.getInstance().setBorderColorSelected(jPanelColorYellow.getBackground());
        }
        if(evt.getButton() == MouseEvent.BUTTON3)
        {
            jPanelSecondaryColor.setBackground(jPanelColorYellow.getBackground());
            Pages.getInstance().setColorSelected(jPanelColorYellow.getBackground());
        }   
    }//GEN-LAST:event_jPanelColorYellowMouseClicked

    private void jPanelColorCyanMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelColorCyanMouseClicked
        
        if(evt.getButton() == MouseEvent.BUTTON1)
        {
            jPanelPrimaryColor.setBackground(jPanelColorCyan.getBackground());
            Pages.getInstance().setBorderColorSelected(jPanelColorCyan.getBackground());
        }
        if(evt.getButton() == MouseEvent.BUTTON3)
        {
            jPanelSecondaryColor.setBackground(jPanelColorCyan.getBackground());
            Pages.getInstance().setColorSelected(jPanelColorCyan.getBackground());
        }
    }//GEN-LAST:event_jPanelColorCyanMouseClicked

    private void jPanelColorDarkBlueMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelColorDarkBlueMouseClicked
        
        if(evt.getButton() == MouseEvent.BUTTON1)
        {
            jPanelPrimaryColor.setBackground(jPanelColorDarkBlue.getBackground());
            Pages.getInstance().setBorderColorSelected(jPanelColorDarkBlue.getBackground());
        }
        if(evt.getButton() == MouseEvent.BUTTON3)
        {
            jPanelSecondaryColor.setBackground(jPanelColorDarkBlue.getBackground());
            Pages.getInstance().setColorSelected(jPanelColorDarkBlue.getBackground());
        }
    }//GEN-LAST:event_jPanelColorDarkBlueMouseClicked

    private void jPanelColorPinkMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelColorPinkMouseClicked
        
        if(evt.getButton() == MouseEvent.BUTTON1)
        {
            jPanelPrimaryColor.setBackground(jPanelColorPink.getBackground());
            Pages.getInstance().setBorderColorSelected(jPanelColorPink.getBackground());
        }
        if(evt.getButton() == MouseEvent.BUTTON3)
        {
            jPanelSecondaryColor.setBackground(jPanelColorPink.getBackground());
            Pages.getInstance().setColorSelected(jPanelColorPink.getBackground());
        }
    }//GEN-LAST:event_jPanelColorPinkMouseClicked

    private void jPanelColorRedMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelColorRedMouseClicked
        
        if(evt.getButton() == MouseEvent.BUTTON1)
        {
            jPanelPrimaryColor.setBackground(jPanelColorRed.getBackground());
            Pages.getInstance().setBorderColorSelected(jPanelColorRed.getBackground());
        }
        if(evt.getButton() == MouseEvent.BUTTON3)
        {
            jPanelSecondaryColor.setBackground(jPanelColorRed.getBackground());
            Pages.getInstance().setColorSelected(jPanelColorRed.getBackground());
        }
    }//GEN-LAST:event_jPanelColorRedMouseClicked

    private void jPanelColorMagentaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelColorMagentaMouseClicked
        
        if(evt.getButton() == MouseEvent.BUTTON1)
        {
            jPanelPrimaryColor.setBackground(jPanelColorMagenta.getBackground());
            Pages.getInstance().setBorderColorSelected(jPanelColorMagenta.getBackground());
        }
        if(evt.getButton() == MouseEvent.BUTTON3)
        {
            jPanelSecondaryColor.setBackground(jPanelColorMagenta.getBackground());
            Pages.getInstance().setColorSelected(jPanelColorMagenta.getBackground());
        }
    }//GEN-LAST:event_jPanelColorMagentaMouseClicked

    private void jPanelColorGreenMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelColorGreenMouseClicked
        
        if(evt.getButton() == MouseEvent.BUTTON1)
        {
            jPanelPrimaryColor.setBackground(jPanelColorGreen.getBackground());
            Pages.getInstance().setBorderColorSelected(jPanelColorGreen.getBackground());
        }
        if(evt.getButton() == MouseEvent.BUTTON3)
        {
            jPanelSecondaryColor.setBackground(jPanelColorGreen.getBackground());
            Pages.getInstance().setColorSelected(jPanelColorGreen.getBackground());
        }
    }//GEN-LAST:event_jPanelColorGreenMouseClicked
    
    private void jButtonSendMessageMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonSendMessageMouseClicked
        Chat.getInstance().send();
    }//GEN-LAST:event_jButtonSendMessageMouseClicked

    private void jTextSendChatBoxKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextSendChatBoxKeyTyped
        if(evt.getKeyChar() == KeyEvent.VK_ENTER) 
        {
            Chat.getInstance().send();
        }
    }//GEN-LAST:event_jTextSendChatBoxKeyTyped

    private void jMenuItemConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemConnectActionPerformed
        jDialogConnectionManager.setVisible(true);
        jDialogConnectionManager.setBounds(400, 350, 270, 220);
    }//GEN-LAST:event_jMenuItemConnectActionPerformed

    private void jMenuItemAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemAboutActionPerformed
        jDialogAbout.setVisible(true);
        jDialogAbout.setBounds(400, 300, 400, 370);
    }//GEN-LAST:event_jMenuItemAboutActionPerformed

    private void jButtonAboutOkMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonAboutOkMouseClicked
        jDialogAbout.setVisible(false);
    }//GEN-LAST:event_jButtonAboutOkMouseClicked

    private void jButtonJoinWorkgroupCancelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonJoinWorkgroupCancelMouseClicked
        jDialogJoinWorkgroup.setVisible(false);
    }//GEN-LAST:event_jButtonJoinWorkgroupCancelMouseClicked

    private void jButtonJoinWorkgroupMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonJoinWorkgroupMouseClicked
        try {
            jLabelJoinWait.setText("please wait");
            ConnexionManager.getInstance().join(
                    jTextFieldWorkgroupName.getText(),
                    jTextFieldWorkgroupPassword.getText());
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(SharedDrawingUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(SharedDrawingUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButtonJoinWorkgroupMouseClicked

    private void jButtonCancelDisconnectionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonCancelDisconnectionMouseClicked
        jDialogConfirmDisconnection.setVisible(false);
    }//GEN-LAST:event_jButtonCancelDisconnectionMouseClicked

    private void jButtonConfirmDisconnectionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonConfirmDisconnectionMouseClicked
        if(askLeave())
        {
            disconnect();
        }
        jDialogConfirmDisconnection.setVisible(false);
        jMenuItemJoin.setEnabled(false);
    }//GEN-LAST:event_jButtonConfirmDisconnectionMouseClicked

    private void jMenuItemJoinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemJoinActionPerformed
        jDialogJoinWorkgroup.setVisible(true);
        jDialogJoinWorkgroup.setBounds(400, 300, 253, 150);
    }//GEN-LAST:event_jMenuItemJoinActionPerformed

    private void jButtonConnectionCancelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonConnectionCancelMouseClicked
        jDialogConnectionManager.setVisible(false);
    }//GEN-LAST:event_jButtonConnectionCancelMouseClicked

    private void jMenuItemDisconnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemDisconnectActionPerformed
        jDialogConfirmDisconnection.pack();
        jDialogConfirmDisconnection.setLocationRelativeTo(this);
        jDialogConfirmDisconnection.setVisible(true);
    }//GEN-LAST:event_jMenuItemDisconnectActionPerformed

    private void jMenuItemQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemQuitActionPerformed
        if(askLeave())
        {
            disconnect();
            System.exit(0);
        }
    }//GEN-LAST:event_jMenuItemQuitActionPerformed

    private void jButtonSavePageListCancelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonSavePageListCancelMouseClicked
        jDialogSaveAll.setVisible(false);
    }//GEN-LAST:event_jButtonSavePageListCancelMouseClicked

    private void jButtonSavePageListSaveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonSavePageListSaveMouseClicked
        
    }//GEN-LAST:event_jButtonSavePageListSaveMouseClicked

    private void jMenuItemSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSaveActionPerformed
        if(jTabbedPaneDrawingContainer.getSelectedIndex()< jTabbedPaneDrawingContainer.getTabCount()-1)
        {
            jFileChooserOpenFile.setApproveButtonText("Save");
            jFileChooserOpenFile.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int returnVal = jFileChooserOpenFile.showOpenDialog(this);
            if(returnVal == JFileChooser.APPROVE_OPTION)
            {
                File file = jFileChooserOpenFile.getSelectedFile();
                List<Page> pagesList = new ArrayList(); 
                pagesList.add((Page)(jTabbedPaneDrawingContainer.getComponentAt(
                        jTabbedPaneDrawingContainer.getSelectedIndex())));
                XmlFile.getInstance().save(file,pagesList);
            }
        }
        else
        {
            JOptionPane.showMessageDialog(
                SharedDrawingUI.getInstance(), 
                "can't save the current page !",
                "ouch",
                JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jMenuItemSaveActionPerformed

    private void jMenuItemSaveAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSaveAllActionPerformed
        saveAll();
    }//GEN-LAST:event_jMenuItemSaveAllActionPerformed

    private void jButtonColorChooserOkMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonColorChooserOkMouseClicked
        
        jDialogSelectColor.setVisible(false);
        if("primary".equals(colorToChange))
        {
            jPanelPrimaryColor.setBackground(jColorChooserPalette.getColor());
            Pages.getInstance().setBorderColorSelected(jColorChooserPalette.getColor());
        }
        if("secondary".equals(colorToChange))
        {
            jPanelSecondaryColor.setBackground(jColorChooserPalette.getColor());
            Pages.getInstance().setColorSelected(jColorChooserPalette.getColor());
        }
    }//GEN-LAST:event_jButtonColorChooserOkMouseClicked

    private void jTabbedPaneDrawingContainerComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jTabbedPaneDrawingContainerComponentShown
        //FIXME : is there anything to do ?
    }//GEN-LAST:event_jTabbedPaneDrawingContainerComponentShown

    private void jPanelnewTabComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jPanelnewTabComponentShown
        // FIXME : is there anything to do ?

    }//GEN-LAST:event_jPanelnewTabComponentShown

    private void jButtonCannotCreateDrawingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCannotCreateDrawingActionPerformed
        jDialogTooManyDrawings.setVisible(false);
    }//GEN-LAST:event_jButtonCannotCreateDrawingActionPerformed

    private void jButtonNewPageCancelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonNewPageCancelMouseClicked
        jDialogNewPage.setVisible(false);
    }//GEN-LAST:event_jButtonNewPageCancelMouseClicked

    private void jButtonNewPageCreateMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonNewPageCreateMouseClicked
        
        if(!jTextFieldNewPageName.getText().isEmpty())
        {
            ConnexionManager.getInstance().newPage(jTextFieldNewPageName.getText());
            addToPageList(jTextFieldNewPageName.getText());
            jDialogNewPage.setVisible(false);
        }
    }//GEN-LAST:event_jButtonNewPageCreateMouseClicked

    private void jTabbedPaneDrawingContainerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPaneDrawingContainerMouseClicked
        if(ConnexionManager.getInstance().isConnected() == true)
        {
            if((evt.getButton() == MouseEvent.BUTTON2))
                if(!"newTab".equals(jTabbedPaneDrawingContainer.getSelectedComponent().getName()))
                {
                    if(jTabbedPaneDrawingContainer.getSelectedComponent() instanceof Page)
                        closePage(jTabbedPaneDrawingContainer.getSelectedIndex());
                    else
                        jTabbedPaneDrawingContainer.remove(jTabbedPaneDrawingContainer.getSelectedComponent());
                }


            if(evt.getButton() == MouseEvent.BUTTON1)
            {
                if("newTab".equals(jTabbedPaneDrawingContainer.getSelectedComponent().getName()))
                {
                    if((jTabbedPaneDrawingContainer.getTabCount() <= 10))
                    {
                        jDialogNewPage.setVisible(true);
                        jDialogNewPage.setBounds(300, 200, WIDTH, WIDTH);
                    }
                    else
                    {
                        jDialogTooManyDrawings.setVisible(true);
                        jDialogTooManyDrawings.setBounds(300, 200, WIDTH, WIDTH);
                    }
                }
                else
                {
                    DrawPage(jTabbedPaneDrawingContainer.getTitleAt(
                            jTabbedPaneDrawingContainer.getSelectedIndex()));
                }
            }
        }
    }//GEN-LAST:event_jTabbedPaneDrawingContainerMouseClicked

    private void jMenuItemCloseCurrentPageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCloseCurrentPageActionPerformed
        if(jTabbedPaneDrawingContainer.getSelectedComponent() instanceof Page)
        {
            closePage(jTabbedPaneDrawingContainer.getSelectedIndex());
        }
    }//GEN-LAST:event_jMenuItemCloseCurrentPageActionPerformed

    private void jMenuItemOpenNewPageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemOpenNewPageActionPerformed
        jDialogNewPage.setVisible(true);
        jDialogNewPage.setBounds(300, 200, WIDTH, WIDTH);
    }//GEN-LAST:event_jMenuItemOpenNewPageActionPerformed

    private void jCheckBoxFillStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBoxFillStateChanged
        Pages.getInstance().setPrimitiveFilled(jCheckBoxFill.isSelected());
    }//GEN-LAST:event_jCheckBoxFillStateChanged

    private void jSliderPrimitiveWidthMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jSliderPrimitiveWidthMouseReleased
        Pages.getInstance().setPrimitiveWidth(jSliderPrimitiveWidth.getValue());
    }//GEN-LAST:event_jSliderPrimitiveWidthMouseReleased

    private void jMenuItemExportPngActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemExportPngActionPerformed
        Component component = jTabbedPaneDrawingContainer.getSelectedComponent();
        Page page;
        if(jTabbedPaneDrawingContainer.getSelectedIndex() < jTabbedPaneDrawingContainer.getTabCount()-1)
        {
            page = (Page) component;
            int returnVal = jFileChooserOpenFile.showOpenDialog(this);
            if(returnVal == JFileChooser.APPROVE_OPTION)
            {   
                File file = jFileChooserOpenFile.getSelectedFile();
                page.toPNG(file.getAbsolutePath());
            }
        }
        else
        {
            JOptionPane.showMessageDialog(
                this, 
                "can't export the current page !",
                "ouch",
                JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jMenuItemExportPngActionPerformed

    private void jMenuItemImportFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemImportFileActionPerformed
        jFileChooserOpenFile.setApproveButtonText("import");
        int returnVal = jFileChooserOpenFile.showOpenDialog(this);
        if(returnVal == JFileChooser.APPROVE_OPTION)
        {   
            File file = jFileChooserOpenFile.getSelectedFile();
            XmlFile.getInstance().upload(file);
        }
    }//GEN-LAST:event_jMenuItemImportFileActionPerformed

    private void jListPageListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jListPageListMouseClicked
        if (evt.getClickCount() == 2) {
            int index = jListPageList.locationToIndex(evt.getPoint());
            ListModel dlm = jListPageList.getModel();
            DrawPage(jListPageList.getSelectedValue().toString());
        }
    }//GEN-LAST:event_jListPageListMouseClicked

    private void jButtonConnectionConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConnectionConnectActionPerformed
        if("".equals(jTextFieldNickName.getText()))
        {
            jLabelConnexionState.setText("can't set an empty name");
        }
        else
        {
            boolean connected = ConnexionManager.getInstance()
                    .connect(jTextFieldNickName.getText(), 
                    jTextFieldHost.getText(),
                    Integer.parseInt(jTextFieldPort.getText())                                                    
                    );
            if(!connected)
            {
                jLabelConnexionState.setText("Connexion Failure");
            }
        }
    }//GEN-LAST:event_jButtonConnectionConnectActionPerformed

    
    
    /**
     * This method is used to clear the chatbox when the user leaves the workgroup
     */
    public void jDialogJoinWorkgroupClear()
    {
        jTextFieldWorkgroupName.setText("");
        jTextFieldWorkgroupPassword.setText("");
    }
    
    public void DrawPage(String title)
    {
        if(getTabByName(title) < 0)
        {
            if(getHiddenTab(title) == null)
            {
                Page page = Pages.getInstance().createPage(title);
                jTabbedPaneDrawingContainer.insertTab(title, null, page, title, 0);
                jTabbedPaneDrawingContainer.getComponentAt(0).setName(title);
                jTabbedPaneDrawingContainer.setSelectedIndex(0);
            }
            else
            {
                Page page = getHiddenTab(title);
                jTabbedPaneDrawingContainer.insertTab(title, null, page, title, 0);
                jTabbedPaneDrawingContainer.setSelectedIndex(0);
                removeFromHiddenTabs(title);
                page.sendIncPageView();
            }
        }
        else
        {
            jTabbedPaneDrawingContainer.getComponentAt(getTabByName(title)).setVisible(true);
            jTabbedPaneDrawingContainer.setSelectedIndex(getTabByName(title));
        }
        jMenuItemSaveAll.setEnabled(true);
        if(!"newTab".equals(jTabbedPaneDrawingContainer.getSelectedComponent().getName()))
        {
            jMenuItemSave.setEnabled(true);
            jMenuItemExportPng.setEnabled(true);
            jMenuItemCloseCurrentPage.setEnabled(true);
        }
        setUserList(title);
    }
    
    /**
     * to get a tab by providing its name
     * @param title the tab we are looking for
     * @return -1 if the tab does not exist. else it returns the index of the tab in the tabbedpane.
     */
    public int getTabByName(String title)
    {
        int ret = -1;
        for(int i = 0;i<jTabbedPaneDrawingContainer.getTabCount();i++)
        {
            if(jTabbedPaneDrawingContainer.getComponentAt(i).getName().compareToIgnoreCase(title) == 0)
            {
                ret = i;
            }
        }
        return ret;
    }
    
    public int getPageListElementByName(String title)
    {
        int ret = -1;
        for(int i = 0;i <jListPageList.getModel().getSize();i++)
        {
            if(jListPageList.getModel().getElementAt(i).toString().compareTo(title) == 0)
                ret = i;
        }
        return ret;
    }
    
    /**
     * to close a page at a given index
     * @param pageIndex the page index
     */
    public void closePage(int pageIndex)
    {
        Page page = (Page)jTabbedPaneDrawingContainer.getComponentAt(pageIndex);
        addHiddenTab(jTabbedPaneDrawingContainer.getComponentAt(pageIndex).getName(), 
                page);
        jTabbedPaneDrawingContainer.remove(pageIndex);
        if(pageIndex >= jTabbedPaneDrawingContainer.getTabCount()-1)
        {
            jMenuItemSave.setEnabled(false);
            jMenuItemSaveAll.setEnabled(false);
            jMenuItemExportPng.setEnabled(false);
            jMenuItemCloseCurrentPage.setEnabled(false);
            setUserList("newTab");
        }
        else
        {
            DrawPage(jTabbedPaneDrawingContainer.getTitleAt(pageIndex));
        }
        page.sendDecPageView();
    }
    
    /**
     * to remove a page from the JList page list
     * @param index the index of the page in the jlist
     */
    public void removeFromPageList(int index)
    {
        ((DefaultListModel)jListPageList.getModel()).remove(index);
    }
    
    /**
     * to add a page to the Jlist page list
     * @param title the title of the page
     */
    public void addToPageList(String title)
    {
        if(getPageListElementByName(title) == -1)
            ((DefaultListModel)jListPageList.getModel()).addElement(title);
    }
    
    /**
     * This method is used to clear the tabbed pane and the jlist when the user leaves the workgroup
     * BUG
     */
    public void clearPages()
    {
        for(int i = 0 ; i < jTabbedPaneDrawingContainer.getTabCount(); i++)
        {
            if(!"newTab".equals(jTabbedPaneDrawingContainer.getComponentAt(i).getName()))
                jTabbedPaneDrawingContainer.remove(i);
        }
        ((DefaultListModel)jListPageList.getModel()).removeAllElements();
    }
    
    /**
     * to add the new user in the user list
     * @param nickname the new user nickname
     */
    public void addToUsersList(String nickname)
    {
        users.put(nickname, false);
        ((DefaultListModel)jListUsersList.getModel()).
                addElement(nickname);
    } 
    
     public void setUserList(String pageName)
    {
        if("newTab".equals(jTabbedPaneDrawingContainer.getSelectedComponent().getName()))
        {
            //clear list
            ((DefaultListModel)jListUsersList.getModel()).
                         removeAllElements();
            //set all to normal
            for(String nickname : users.keySet())
            {
                users.put(nickname, false);
            }
            //fill list
            for(String nickname : users.keySet())
            {
                ((DefaultListModel)jListUsersList.getModel()).
                        addElement(nickname);
            }
        }
        else
        {
            //set all to normal
            for(String nickname : users.keySet())
            {
                users.put(nickname, false);
            }
            //set viewers
            for(String viewerId : Pages.getInstance().getPage(pageName).getViews())
            {
                if(!viewerId.equals(ConnexionManager.getInstance().getUserId()))
                {
                    String nickname = ConnexionManager.getInstance().getNickName(viewerId);
                    if(nickname == null)
                    {
                        users.remove(viewerId);
                    }
                    else
                    {
                        users.put(nickname, true);
                    }
                }
            } 
            //clear list
            ((DefaultListModel)jListUsersList.getModel()).
                            removeAllElements();
            //fill list
            for(String nickname : users.keySet())
            {
                String suffix = "";
                if(users.get(nickname))
                    suffix=" (has the current page open)";
                ((DefaultListModel)jListUsersList.getModel()).
                        addElement(nickname + suffix);
            }
        }
    }
    
    /**
     * to remove a user from the user
     * @param nickname the user nickname
     */
    public void removeFromUserList(String nickName)
    {
        users.remove(nickName);
        setUserList(jTabbedPaneDrawingContainer.getTitleAt(
                jTabbedPaneDrawingContainer.getSelectedIndex()));
    }

    
    public void jListUsersListClear()
    {
        DefaultListModel dlm = (DefaultListModel)jListUsersList.getModel();
        dlm.removeAllElements();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAboutOk;
    private javax.swing.JButton jButtonCancelDisconnection;
    private javax.swing.JButton jButtonCannotCreateDrawing;
    private javax.swing.JButton jButtonColorChooserOk;
    private javax.swing.JButton jButtonConfirmDisconnection;
    private javax.swing.JButton jButtonConnectionCancel;
    private javax.swing.JButton jButtonConnectionConnect;
    private javax.swing.JButton jButtonJoinWorkgroup;
    private javax.swing.JButton jButtonJoinWorkgroupCancel;
    private javax.swing.JButton jButtonNewPageCancel;
    private javax.swing.JButton jButtonNewPageCreate;
    private javax.swing.JButton jButtonSavePageListCancel;
    private javax.swing.JButton jButtonSavePageListSave;
    private javax.swing.JButton jButtonSendMessage;
    private javax.swing.JCheckBox jCheckBoxFill;
    private javax.swing.JColorChooser jColorChooserPalette;
    private javax.swing.JDialog jDialogAbout;
    private javax.swing.JDialog jDialogConfirmDisconnection;
    private javax.swing.JDialog jDialogConnectionManager;
    private javax.swing.JDialog jDialogJoinWorkgroup;
    private javax.swing.JDialog jDialogNewPage;
    private javax.swing.JDialog jDialogOpenFile;
    private javax.swing.JDialog jDialogSaveAll;
    private javax.swing.JDialog jDialogSelectColor;
    private javax.swing.JDialog jDialogTooManyDrawings;
    private javax.swing.JFileChooser jFileChooserOpenFile;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabelAboutClement;
    private javax.swing.JLabel jLabelAboutLeo;
    private javax.swing.JLabel jLabelAboutMathias;
    private javax.swing.JLabel jLabelAboutMickael;
    private javax.swing.JLabel jLabelConnexionState;
    private javax.swing.JLabel jLabelHost;
    private java.awt.Label jLabelJoinWait;
    private javax.swing.JLabel jLabelNewPageName;
    private javax.swing.JLabel jLabelNickName;
    private javax.swing.JLabel jLabelPort;
    private javax.swing.JLabel jLabelStatusBar;
    private javax.swing.JLabel jLabelTooManyDrawings;
    private javax.swing.JLabel jLabelWorkgroupName;
    private javax.swing.JLabel jLabelWorkgroupPassword;
    private static javax.swing.JList jListPageList;
    private static javax.swing.JList jListUsersList;
    private javax.swing.JMenuBar jMenuBarMenuSet;
    private javax.swing.JMenu jMenuEdit;
    private javax.swing.JMenu jMenuFile;
    private javax.swing.JMenu jMenuHelp;
    private javax.swing.JMenuItem jMenuItemAbout;
    private javax.swing.JMenuItem jMenuItemCloseCurrentPage;
    private javax.swing.JMenuItem jMenuItemConnect;
    private javax.swing.JMenuItem jMenuItemDisconnect;
    private javax.swing.JMenuItem jMenuItemExportPng;
    private javax.swing.JMenuItem jMenuItemImportFile;
    private javax.swing.JMenuItem jMenuItemJoin;
    private javax.swing.JMenuItem jMenuItemLeave;
    private javax.swing.JMenuItem jMenuItemOpenNewPage;
    private javax.swing.JMenuItem jMenuItemQuit;
    private javax.swing.JMenuItem jMenuItemSave;
    private javax.swing.JMenuItem jMenuItemSaveAll;
    private javax.swing.JMenu jMenuServer;
    private javax.swing.JMenu jMenuWorkgroup;
    private javax.swing.JPanel jPanelAboutAuthors;
    private javax.swing.JPanel jPanelAboutInformation;
    private javax.swing.JPanel jPanelBounding;
    private javax.swing.JPanel jPanelChatContainer;
    private javax.swing.JPanel jPanelColorBlack;
    private javax.swing.JPanel jPanelColorBrown;
    private javax.swing.JPanel jPanelColorCyan;
    private javax.swing.JPanel jPanelColorDarkBlue;
    private javax.swing.JPanel jPanelColorGreen;
    private javax.swing.JPanel jPanelColorGrey;
    private javax.swing.JPanel jPanelColorMagenta;
    private javax.swing.JPanel jPanelColorOrange;
    private javax.swing.JPanel jPanelColorPink;
    private javax.swing.JPanel jPanelColorRed;
    private javax.swing.JPanel jPanelColorWhite;
    private javax.swing.JPanel jPanelColorYellow;
    private javax.swing.JPanel jPanelColors;
    private javax.swing.JPanel jPanelParameters;
    private javax.swing.JPanel jPanelPrimaryColor;
    private javax.swing.JPanel jPanelPrimitiveWidth;
    private static javax.swing.JPanel jPanelPrimitives;
    private javax.swing.JPanel jPanelSecondaryColor;
    private javax.swing.JPanel jPanelStatusBar;
    private javax.swing.JPanel jPanelnewTab;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPaneChatInput;
    private javax.swing.JScrollPane jScrollUserList;
    private javax.swing.JSlider jSliderPrimitiveWidth;
    private static javax.swing.JTabbedPane jTabbedPaneDrawingContainer;
    private javax.swing.JTable jTableSavePageList;
    private static javax.swing.JTextArea jTextAreaChatBox;
    private javax.swing.JTextArea jTextAreaWelcomeMessage;
    private javax.swing.JTextField jTextFieldHost;
    private javax.swing.JTextField jTextFieldNewPageName;
    private javax.swing.JTextField jTextFieldNickName;
    private javax.swing.JTextField jTextFieldPort;
    private javax.swing.JTextField jTextFieldWorkgroupName;
    private javax.swing.JTextField jTextFieldWorkgroupPassword;
    private static javax.swing.JTextPane jTextSendChatBox;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables

    

}
